/*
 * @Author: 🐝小蜜蜂🐝 
 * @Date: 2023-04-25 22:03:24
 * @LastEditTime: 2023-04-25 22:36:49
 * @LastEditors: 🐝小蜜蜂🐝 
 * @Description: 
 * @FilePath: /handheld-terminal-app/lib/pages/scrap_enter_page.dart
 * @CopyRight：小蜜蜂🐝  QQ：834537795
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:material_collection_app/pages/enter_tab_page.dart';
import 'package:material_collection_app/widget/common/tabbar_custom.dart';
import 'package:material_collection_app/widget/common/search_box.dart';
import 'package:material_collection_app/widget/common/top_bar.dart';

/// 报废入库页面
class ScrapEnterPage extends StatefulWidget {
  final Map arguments;
  ScrapEnterPage({Key key, this.arguments}) : super(key: key);

  @override
  State<StatefulWidget> createState() => MyState();
}

class MyState extends State<ScrapEnterPage>
    with SingleTickerProviderStateMixin {
  String validStartDate;
  String validEndDate;
  String enStartDate;
  String enEndDate;
  String keywords = '';
  List tabs = ['待接收', '待清点', '已清点'];
  List tabsStatus = [
    {'status': 'accept', 'index': 0},
    {'status': 'check', 'index': 1},
    {'status': 'checked', 'index': 2},
  ];

  TabController _tabController;
  TextEditingController _searchController = TextEditingController();

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: tabs.length);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
    List<Key> keys = [acceptKey, checkKey, checkedKey];

    return Scaffold(
        appBar: TopBar(
          height: 0,
        ),
        body: SafeArea(
            child: Container(
                color: Color(0xFF297CFF),
                child: Column(children: <Widget>[
                  SearchBox(
                      hintText: '名称',
                      endDrawer: true,
                      searchController: _searchController,
                      onSearch: (value) {
                        setState(() {
                          keywords = value;
                        });

                        int index = _tabController.index;
                        if (index == 0) acceptKey.currentState.search();
                        if (index == 1) checkKey.currentState.search();
                        if (index == 2) checkedKey.currentState.search();
                      }),
                  Expanded(
                      child: DefaultTabController(
                          length: tabs.length,
                          initialIndex: 0,
                          child: Column(children: <Widget>[
                            TabBarCustom(
                              tabs: tabs,
                              tabController: _tabController,
                            ),
                            Expanded(
                                child: TabBarView(
                                    controller: _tabController,
                                    children: tabsStatus.map((item) {
                                      return EnterTabPage(
                                        baseApi: 'scrap_enter/',
                                        status: item['status'],
                                        keywords: keywords,
                                        key: keys[item['index']],
                                      );
                                    }).toList()))
                          ])))
                ]))));
  }
}
